//瓶身做个物体
// urp的lit瓶子做个半透明 ，surface Type to transparent
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

//挂在相机上
public class wobble :MonoBehaviour{


	
    public GraphicsLevel graphicLevel;
    public float MaxWobble = 0.05f;
    public float WobbleSpeed = 1.0f;
    public float Recovery = 1.0f;


   void Start()
    {
        rend = GetComponent<Renderer>();
    }

   
    void Update()
    {
        time += Time.deltaTime;
        wobbleAmoutToAddX = Mathf.lerp(wobbleAmoutToAddX,0, Time.deltaTime * (Recovery));
        wobbleAmoutToAddZ = Mathf.lerp(wobbleAmoutToAddZ,0, Time.deltaTime * (Recovery));

        pulse = 2* Mathf.PI * WobbleSpeed ;
        wobbleAmoutX = Mathf.Sin(pulse * time) * wobbleAmoutToAddX;
        wobbleAmoutZ = Mathf.Sin(pulse * time) * wobbleAmoutToAddZ;

        rend.material.SetFloat("_WobbleX",wobbleAmoutX);
        rend.material.SetFloat("_WobbleZ",wobbleAmoutZ);

        velocity = (lastPos - transform.position) / Time.deltaTime;
        angularVelocity = transform.rotation.eulerAngles - lastRot;

        velocity =(lastPos - transform.position) / Time.deltaTime;
        angularVelocity = transform.rotation.eulerAngles - lastRot;

        wobbleAmoutToAddX = Mathf.Clamp(velocity.magnitude * MaxWobble,0,MaxWobble);
        wobbleAmoutToAddZ = Mathf.Clamp(velocity.magnitude * MaxWobble,0,MaxWobble);
        
        lastPos = transform.position;
        lastRot = transform.rotation.eulerAngles;

        


    }
}
